import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  //存放数据信息
  state:{
    token:{},
    user:{},
    activity: "",
  },
  getters:{
      getActivity : state=>{
          let activity = state.activity;
          if(!activity.length){
              activity = window.sessionStorage.getItem('activity');
          }
          return activity;
      },
  },
  //数据操作通道
  mutations:{
    setActivity : (state,activity) => {
      state.activity = activity;
      window.sessionStorage.setItem('activity',activity);
    },
    setToken(state,token){
      state.token=token;
      sessionStorage.setItem("token",token);
    },
    removeToken(state,token){
      state.token = "";
      sessionStorage.removeItem("token");
    }
  }
})
